package com.dongzili.demo.customer.es.controller;

import com.dongzili.demo.common.config.base.BaseService;
import com.dongzili.demo.common.config.es.EsUtils;
import com.dongzili.demo.common.vo.ApiResponse;
import com.dongzili.demo.customer.model.Relation;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/es")
public class EsTestController {

    @RequestMapping("/search")
    public ApiResponse<?> search(@RequestParam String keyword) {
        LambdaEsQueryWrapper<Relation> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.like(Relation::getResName, keyword);
        EsPageInfo<Relation> pageInfo = EsUtils.getMapper(Relation.class).pageQuery(wrapper, 1, 10);
        return ApiResponse.success(pageInfo);
    }

    @PostMapping("/insert")
    public ApiResponse<?> insert(@RequestBody Relation relation) {
        return ApiResponse.success(BaseService.getService(Relation.class).insert(relation));
    }

    @PostMapping("/update")
    public ApiResponse<?> update(@RequestBody Relation relation) {
        return ApiResponse.success(BaseService.getService(Relation.class).insert(relation));
    }
}
